import Vue from 'vue'
import Router from 'vue-router'
import Index from '@/view/Index'

Vue.use(Router)

const router = new Router({
    base: '/home/',
    routes: [{
            path: '/',
            name: 'index',
            component: Index
        },
        {
            path: '/home',
            name: 'home',
            component: resolve => require(['../view/Home.vue'], resolve),
            children: [{
                path: '/frontUser',
                name: '前端用户管理',
                component: resolve => require(['../view/user/frontUser.vue'], resolve)},
                {
                    path: '/users',
                    name: '用户列表',
                    component: resolve => require(['../view/user/Users.vue'], resolve)
                }, {
                    path: '/roles',
                    name: '角色列表',
                    component: resolve => require(['../view/user/Roles.vue'], resolve)
                },
                {
                    path: '/organization',
                    name: '机构列表',
                    component: resolve => require(['../view/user/Organization.vue'], resolve)
                },
                {
                    path: '/expert',
                    name: '专家列表',
                    component: resolve => require(['../view/expert/Expert.vue'], resolve)
                },
                {
                    path: '/domain',
                    name: '领域管理',
                    component: resolve => require(['../view/expert/Domain.vue'], resolve)
                },
                {
                    path: '/article',
                    name: '新增/修改',
                    component: resolve => require(['../view/article/Article.vue'], resolve)
                },
                {
                    path: '/articleType',
                    name: '文章分类',
                    component: resolve => require(['../view/article/ArticleType.vue'], resolve)
                },
                {
                    path: '/articlelist',
                    name: '文章列表',
                    component: resolve => require(['../view/article/ArticleList.vue'], resolve)
                },
                {
                    path: '/indexpic',
                    name: '首页图片管理',
                    component: resolve => require(['../view/file/Pic.vue'], resolve)
                },
                {
                    path: '/video',
                    name: '视频管理',
                    component: resolve => require(['../view/file/Video.vue'], resolve)
                }, {
                    path: '/friend',
                    name: '友情链接',
                    component: resolve => require(['../view/friendly/friendly.vue'], resolve)
                },
                {
                    path: '/demo',
                    name: 'demo',
                    component: resolve => require(['../view/Demo.vue'], resolve)
                },
                {
                  path: '/notice',
                  name: '公告列表',
                  component: resolve => require(['../view/notice/noticeList.vue'], resolve)
                },
                {
                  path: '/project',
                  name: '课题列表',
                  component: resolve => require(['../view/project/projectList.vue'], resolve)
                },
                {
                  path: '/projectType',
                  name: '课题分类',
                  component: resolve => require(['../view/project/projectType.vue'], resolve)
                },
                {
                  path: '/downloadList',
                  name: '下载文件列表',
                  component: resolve => require(['../view/download/downloadList.vue'], resolve)
                }

            ]
        },

    ]
})


router.beforeEach((to, from, next) => {
    console.log("路由", router.app.$options.store.getters.getUser.username)
    let user = router.app.$options.store.getters.getUser.username

    if (to.path == '/') {
        next()
    } else {
        if (user) {
            next()
        } else {
            next('/')
        }
    }

})


export default router
